class LastPageMiddleware(object):
    def __init__(self,app,exceptPaths=[],exceptControllers=[],excpetActions=[]):
        self.app=app
        self.exceptPaths=map(unicode,exceptPaths)
        self.exceptControllers=map(unicode,exceptControllers)
        self.exceptActions=map(unicode,excpetActions)

    def __call__(self,environ,start_response):
        session=environ['beaker.session']
        path=environ['PATH_INFO']
        controller=environ['wsgiorg.routing_args'][1].get('controller','')
        action = environ['wsgiorg.routing_args'][1].get('action','')
        if not (path in self.exceptPaths) and not (action in self.exceptActions) \
                and not (controller in self.exceptControllers): session['last']=path
        return self.app(environ,start_response)

